using System;
using System.Collections.Generic;
using System.Text;
using System.Data;



namespace THSLib
{
    #region STScreensController
    /// <summary>
    /// This object represents the properties and methods of a Screen.
    /// </summary>
    public class STScreensController:BaseBusinessController
    {
        #region SP Name
        //Select By ForeignKey Queries
        /*Remove cause of not use
        private readonly string spGetSTScreensBySTUserGroupID = "STScreens_SelectBySTUserGroupID";
        private readonly string spGetSTScreensBySTModuleID = "STScreens_SelectBySTModuleID";*/

        //Select By all foreignkey query
        private readonly string spGetSTScreensBySTUserGroupIDAndSTModuleID =
                               "STScreens_SelectBySTUserGroupIDAndSTModuleID";
        private readonly string spGetSTScreensBySTModuleNameAndADUserGroupName =
                               "STScreens_SelectBySTModuleNameAndADUserGroupName";
        private readonly string spGetSTScreensBySTModuleName =
                               "STScreens_SelectBySTModuleName";
        private readonly string spGetSTScreensBySTModuleIDAndSTUserGroupIDAndSTScreenName =
                               "STScreens_SelectBySTModuleIDAndSTUserGroupIDAndSTScreenName";
        private readonly string spGetSTScreensBySTModuleNameAndADUserGroupNameAndSTScreenName =
                               "STScreens_SelectBySTModuleNameAndADUserGroupNameAndSTScreenName";

        private readonly string spGetSTScreensBySTModuleIDAndSTUserGroupIDAndSTScreenNumber=
                                "STScreens_SelectBySTModuleIDAndSTUserGroupIDAndSTScreenNumber";

        //Delete by foreignkey Queries
        /*Remove cause of not use
        private readonly string spDeleteSTScreensBySTUserGroupID = "STScreens_DeleteBySTUserGroupID";
        private readonly string spDeleteSTScreensBySTModuleID = "STScreens_DeleteBySTModuleID";*/
        private readonly string spDeleteSTScreensBySTModuleIDAndSTUserGroupID =
                                "STScreens_DeleteBySTModuleIDAndSTUserGroupID";

        #endregion
        public STScreensController()
        {
            //dal = new STScreensDAL();
            dal = new DALBaseProvider("STScreens", typeof(STScreensInfo));
        }
        
        
        public DataSet GetScreenByUserGroupIDAndModuleID(int iUserGroupID, int iModuleID)
        {
            return (DataSet)dal.GetDataSet(spGetSTScreensBySTUserGroupIDAndSTModuleID,iModuleID,iUserGroupID);            
        }

        public DataSet GetScreenByModuleName(String strModuleName)
        {
            return (DataSet)dal.GetDataSet(spGetSTScreensBySTModuleName, strModuleName);            
        }

        public DataSet GetScreenByModuleNameAndUserGroupName(String strModuleName, String strUserGroupName)
        {
            StringBuilder queryBuilder = new StringBuilder();
            queryBuilder.Append("SELECT s.* FROM STScreens s");
            queryBuilder.Append(THSUtil.NewLine + "INNER JOIN STModules m ON s.STModuleID = m.STModuleID");
            queryBuilder.Append(THSUtil.NewLine + "INNER JOIN ADUserGroups g ON s.STUserGroupID = g.ADUserGroupID");
            queryBuilder.Append(THSUtil.NewLine + String.Format("WHERE m.STModuleName = '{0}' AND g.ADUserGroupName = '{1}'", strModuleName, strUserGroupName));
            queryBuilder.Append("ORDER BY s.STScreenSortOrder");
            return (DataSet)dal.GetDataSet(queryBuilder.ToString());            
        }

        public STScreensInfo GetScreenByModuleIDAndUserGroupIDAndScreenName(int iModuleID, int iUserGroupID, String strScreenName)
        {
            return (STScreensInfo)dal.GetDataObject(spGetSTScreensBySTModuleIDAndSTUserGroupIDAndSTScreenName,iModuleID,iUserGroupID,strScreenName);
        }

        public STScreensInfo GetSTScreensByModuleIDAndUserGroupIDAndScreenNumber(int iModuleID, int iUserGroupID, String strScreenNumber)
        {
            return (STScreensInfo)dal.GetDataObject(spGetSTScreensBySTModuleIDAndSTUserGroupIDAndSTScreenNumber,
                                                    iModuleID, iUserGroupID, strScreenNumber);

        }

        public int GetScreenIDByModuleIDAndUserGroupIDAndScreenName(int iModuleID, int iUserGroupID, String strScreenName)
        {
            int iScreenID = 0;
            STScreensInfo objSTScreensInfo = GetScreenByModuleIDAndUserGroupIDAndScreenName(iModuleID, iUserGroupID, strScreenName);
            if (objSTScreensInfo != null)
                iScreenID = objSTScreensInfo.STScreenID;
            return iScreenID;
        }
        

        public STScreensInfo GetScreenByModuleNameAndUserGroupNameAndScreenName(String strModuleName, String strUserGroupName, String strScreenName)
        {
            return (STScreensInfo)dal.GetDataObject(spGetSTScreensBySTModuleNameAndADUserGroupNameAndSTScreenName, strModuleName, strUserGroupName, strScreenName);            
        }

        public int GetScreenIDByModuleNameAndUserGroupNameAndScreenName(String strModuleName, String strUserGroupName, String strScreenName)
        {
            int iScreenID = 0;
            STScreensInfo objSTScreensInfo = GetScreenByModuleNameAndUserGroupNameAndScreenName(strModuleName, strUserGroupName, strScreenName);
            if (objSTScreensInfo != null)
                iScreenID = objSTScreensInfo.STScreenID;
            return iScreenID;
            
        }

        public void DeleteScreensBySTModuleIDAndSTUserGroupID(int iSTModuleID, int iSTUserGroupID)
        {
            dal.GetDataSet(spDeleteSTScreensBySTModuleIDAndSTUserGroupID, iSTModuleID, iSTUserGroupID);
        }
    }
    #endregion
}
